1826C - Dreaming of Freedom - CodeForces Solution


greedy number theory

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define count_1(n)   __builtin_popcountll(n)
#define pb push_back
#define fr(a,b) for(int i =a ;i <b ;i++)
#define fr1(a,b) for(int j =a ;j <b ;j++)
#define all(x) (x).begin(), (x).end()
#define vint vector<int>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e9 + 7 ;
#define inf (1LL<<62)
template <typename T>istream &operator>>(istream &istream, vector<T> &vec){for (auto &a : vec)cin >> a;return istream;}     
template <typename T>ostream &operator<<(ostream &ostream, const vector<T> &vec){for (auto &a : vec)cout << a << " ";return ostream;}
long long binpow(long long a, long long b) {
long long res = 1;
    while (b > 0) {
        if (b & 1) res = res * a; a = a * a; b >>= 1;
    } return res;
}   

//==========================================-_-=============================================// 
ll smallestDivisor(ll n)
{
    if (n % 2 == 0)
        return 2;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }
 
    return n;
}
int main() {
    FAST
    ll t,n,m,x,j,k,q,d,e;
    t=1;
    cin>>t;
    while(t--){
        ll ans=0,a=0,b=0,l,r,mid;
      cin>>n>>m;
      if(m>=n&&n!=1){
          cout<<"no"<<endl;
      }
      else{
          if(n%m==0&&n!=1&&m!=1){
              cout<<"No"<<endl;
          }
          else if(n==1||m==1){
              cout<<"yes"<<endl;
          }
          else{
              k=smallestDivisor(n);
              
              if(k<=m&&k!=1){
                  cout<<"no"<<endl;
              }
              else cout<<"yes"<<endl;
          }
      }
    }
    return 0;
   }


Comments

Submit
0 Comments
More Questions

1114A - Got Any Grapes
224B - Array
125B - Simple XML
567B - Berland National Library
431B - Shower Line
282C - XOR and OR
1582B - Luntik and Subsequences
609A - Флеш-карты
1207A - There Are Two Types Of Burgers
371C - Hamburgers
343B - Alternating Current
758B - Blown Garland
1681B - Card Trick
1592A - Gamer Hemose
493D - Vasya and Chess
1485A - Add and Divide
337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height